/*
 Copyright (c) Whitemice Consulting, 2007, 2008, 2009
 Adam Tauno Williams <awilliam@whitemice.org>
 License: MIT/X11

 Permission is hereby granted, free of charge, to any person obtaining a copy
 of this software and associated documentation files (the "Software"), to deal
 in the Software without restriction, including without limitation the rights
 to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
 copies of the Software, and to permit persons to whom the Software is
 furnished to do so, subject to the following conditions:

 The above copyright notice and this permission notice shall be included in
 all copies or substantial portions of the Software.
 
 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
 AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
 OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
 THE SOFTWARE.
*/
using System;
using Gtk;
using System.Collections.Generic;
using HollyLibrary;
using Whitemice.ZOGI;
using Whitemice.ZOGI.GtkWidgets;

namespace Whitemice.ZOGI.GtkFolios
{
  [System.ComponentModel.Category("Folios")]
  [System.ComponentModel.ToolboxItem(true)]
  public partial class DocumentsTab : Gtk.Bin, IEntityForm, IZOGIWidget
  { 
    protected MultiResultCallback                rootFolderCallback;
    
    public DocumentsTab()
    {
      this.Build();
      this.rootFolderCallback = new MultiResultCallback(this.ReceiveDataCallback);
    }
    
 		public void Fill(Entity entity)
		{
		  Project       project = null;
      FetchCommand  command;
		  
		  if (entity is Whitemice.ZOGI.Enterprise)
		    project = (entity as Whitemice.ZOGI.Enterprise).Project;
		  else if (entity is Whitemice.ZOGI.Project)
		    project = (entity as Whitemice.ZOGI.Project);
      if (project != null)
      {
        command = new FetchCommand(project.FolderId, 65535, null);
        command.Callback = rootFolderCallback;
        Server.Connection.RunCommand(command);
      }
		} // end Fill
		
		public void Clear()
		{
		} // end Clear
		
		public void ReceiveRPCCall(RPCEventArgs args)
		{
      //TODO: Implement RPC reception in documents tab
      //if (result is Whitemice.ZOGI.Folder)
      //  ProcessFolder(null, result);
		} // end ReceiveRootFolder
		
		protected virtual void ProcessFolder(HTreeNode root, Entity result, object context, Exception exception)
		{
		  /*
		  if (result is Whitemice.ZOGI.Folder)
		  {
		    Folder folder = (result as Whitemice.ZOGI.Folder);
		    foreach(Entity e in folder.Children)
		    {
		      if (e is Whitemice.ZOGI.File) 
		      {
		        InsertFile(root, (e as Whitemice.ZOGI.File));
		      } else if (e is Whitemice.ZOGI.Folder)
		        {
		          node = InsertFile(root, (e as Whitemice.ZOGI.Folder));
		        }
		    } // end foreach-Children
		   }
		   */
		} // end ProcessFolder
		
		/*
		protected virtual HTreeNode InsertFile(HTreeNode root, Whitemice.ZOGI.File file)
		{
		  HTreeNode node;
		  
		  node = new HTreeNode(file.Title);
		  if (root == null)
		    explorer.Nodes.Add(node);
		  else root.Nodes.Add(node);
		} // end InsertFile
		
		protected virtual HTreeNode InsertFolder(HTreeNode root, Whitemice.ZOGI.Folder folder)
		{
		  HTreeNode node;
		  
		}
    */
		protected virtual void OnCheckoutFileClicked (object sender, System.EventArgs e)
		{
		}

		protected virtual void OnRenameFileClicked (object sender, System.EventArgs e)
		{
		}

		protected virtual void OnUploadFileClicked (object sender, System.EventArgs e)
		{
		}

		protected virtual void OnSendFileClicked (object sender, System.EventArgs e)
		{
		}

		protected virtual void OnSaveFileClicked (object sender, System.EventArgs e)
		{
		}

		protected virtual void OnEditFileClicked (object sender, System.EventArgs e)
		{
		}

		protected virtual void OnDeleteFileClicked (object sender, System.EventArgs e)
		{
		}

		protected virtual void OnReleaseFileClicked (object sender, System.EventArgs e)
		{
		}

		protected virtual void OnUploadClicked (object sender, System.EventArgs e)
		{
		}

		protected virtual void OnTextClicked (object sender, System.EventArgs e)
		{
		}
  }
}